import '@/public-path'
import { createApp } from 'vue'
// import plugin from '@/plugins'
import global from '@/global'
import router from '@/router'
import directive from '@/directive'
import App from './App.vue'

let app = null

const render = (props = {}) => {
  const { container } = props
  app = createApp(App)
  app
    .use(global)
    .use(directive)
    .use(router)
    .mount(container ? container.querySelector('#micro-app') : '#app')
}

// 独立运行
if (!window.__POWERED_BY_QIANKUN__) {
  render()
}

export async function bootstrap() {
  // console.log('vue: bootstrap')
}
export async function mount(props) {
  // console.log('vue: mount')
  render(props)
}
export async function unmount() {
  // console.log('vue: unmount')
  app.unmount()
  app._container.innerHTML = ''
  app = null
}
